package com.job.admin.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.job.admin.framework.springmvc.BaseController;
import com.job.admin.user.model.UserModel;
import com.job.admin.user.service.UserService;
/**
 * 
 * @Title: LoginController.java
 * @Package: com.job.admin.controller
 * @Description: 首页收录信息
 * @author: sunwei
 * @date: 2017年5月20日 下午1:10:58
 * @version: V1.0
 */
@Controller("/")
public class IndexController extends BaseController {
    static{
	System.out.println("controller初始化了");
    }
    @Resource
    private UserService userService;
    @RequestMapping("/login")
    public String login(HttpServletRequest request,HttpServletResponse response,UserModel model){
	return "login/login";
    }
    @RequestMapping("/toLogin")
    @ResponseBody
    public String toLogin(HttpServletRequest request,HttpServletResponse response,UserModel model){
	UserModel userModel=userService.getUserModel(model);
	if(null==userModel || StringUtils.isEmpty(model.getUserName()) || StringUtils.isEmpty(model.getUserPassword())){
	    return jsonStrAndState(null, false, "用户名或密码错误");
	}
//	if(!PermissionInterceptor.ifLogin(request, userModel)){//如果没有登陆过
//	    boolean ifRemeber=false;
//	    if(model.isIfRemeber()){//记住登陆
//		ifRemeber=true;
//	    }
//	    PermissionInterceptor.login(response, userModel, ifRemeber);
//	}
	return  jsonStrAndState("page/main.jsp", true, "登陆成功");
    }
    @RequestMapping("/")
    @Override
    public String getPath(HttpServletRequest request) {
	return "index";
    }
    
    
}
